$(function (){
    //获取用户信息
    let user = sessionStorage.getItem('userInfo');
    user = JSON.parse(user);
    if (user != null){
        let id = user.userInfoId+'';
        let idArr = id.split('');
        idArr[3] = '*'
        idArr[4] = '*'
        idArr[5] = '*'
        $('.name').find('span').text(idArr.join(''))
        $('#noLogin').css('display','none');
        $('.my-nav').css('display','flex');
        $('#my').find('img').prop('src','../image/foreground/2.webp')
        $("#user").text(user.userInfoName)
        $('#total').css('display','inline-block')
        $.post('../picture/getPictureList',{ userInfoId:user.userInfoId},function (total){
            $('#total span').text(total);
            $('#total2').text(total)
        })
    }

    function ifLogin(){
        if (user == null){
            return false;
        }
        return true;
    }

    $('#me').on('click',function (){
        if (ifLogin()){
            window.location.href = '../personal.html';
        }else {
            jumpUser();
        }
    })
    $('#my').on('click',function (){
        if (ifLogin()){
            window.location.href = '../personal.html';
        }else {
            jumpUser();
        }
    })
    $('#user').on('click',function (){
        if (ifLogin()){
            window.location.href = '../userInfologin.html';
        }else {
            jumpUser();
        }
    })

    $('#goShoppingCart').on('click',function (){
        if (ifLogin()){
            window.location.href = '../shoppingCart.html';
        }else {
            jumpUser();
        }
    })

    function jumpUser(){
        // 设置登录完成后的跳转URL
        const currentUrl = window.location.href;
        sessionStorage.setItem('redirectUrl', currentUrl);
        window.location.href = '../userInfologin.html';
    }
})